package com.lh.service.impl;

import com.alibaba.excel.util.StringUtils;
import com.alibaba.fastjson.JSONObject;
import com.lh.entity.table.SignReceipt;
import com.lh.mapper.SignReceiptMapper;
import com.lh.service.SignReceiptService;
import com.lh.utils.Answer;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

@Service
public class SignReceiptServiceImpl implements SignReceiptService {

    @Resource
    private SignReceiptMapper signReceiptMapper;

    @Override
    public Answer<Object> addSignReceipt(JSONObject reqJson) {
        Integer rectificationId = reqJson.getInteger("rectificationId");
        String receiptDepartment = reqJson.getString("receiptDepartment");
        if (rectificationId==null){
            return Answer.error("任务id为空");
        }
        if (StringUtils.isBlank(receiptDepartment)){
            return Answer.error("签收部门为空");
        }
        SignReceipt signReceipt = new SignReceipt();
        signReceipt.setReceiptTime(new Date());
        signReceipt.setRectificationId(rectificationId);
        signReceipt.setReceiptDepartment(receiptDepartment);
        signReceiptMapper.insert(signReceipt);
        return Answer.ok("签收完成");
    }

    @Override
    public Answer<Object> getSignReceipt(JSONObject reqJson) {
        String receiptDepartment = reqJson.getString("receiptDepartment");
        return Answer.ok(receiptDepartment);
    }
}
